package com.weeego.web.base;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

public class BaseClass {

	protected final Logger logger = Logger.getLogger(getClass());
	
	public String toString() {
		try {
			Map<Object, Object> map;
			map = BeanUtils.describe(this);

			Iterator<Object> keyIt = map.keySet().iterator();
			StringBuilder builder = new StringBuilder(this.getClass().getName()
					+ ": [ ");
			int i = 0;
			while (keyIt.hasNext()) {
				String key = (String) keyIt.next();

				if ("class".equals(key)) {
					continue;
				}
				Object value = map.get(key);

				if (i > 0) {
					builder.append(", ");
				}

				builder.append(key + " = " + value + "");
				i++;
			}
			builder.append(" ]");
			return builder.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return super.toString();
		}
	}
}
